//
//  DATSprite.m
//  MapEdit
//
//  Created by Steven Canfield on 28/06/07.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "DATSprite.h"

#define NUM_SPRITE 517

@implementation DATSprite

- (id)initWithData:(NSData *)data {
	self = [super init];
	if( self ) {
		sprites = malloc( sizeof( dat_sprite_t ) * NUM_SPRITE );
		
		int spriteIndex;
		int dataIndex = 0;
		for( spriteIndex = 0; spriteIndex < NUM_SPRITE; spriteIndex++ ) {
			/* Read Unit Info */
			u_int16_t buff16;
			[data getBytes:&buff16 range:NSMakeRange( dataIndex, sizeof( u_int16_t ))];
			buff16 = NSSwapLittleShortToHost( buff16 );
			dataIndex += sizeof( u_int16_t );
			sprites[ spriteIndex ].image_index = buff16;
		}
	}
	return self;
}


- (dat_sprite_t *)spriteAtIndex:(int)index {
	//NSLog(@"%@ => %i", NSStringFromSelector(_cmd), index );
	return &(sprites[ index ]);
}
@end
